<?php
include '../dbconnect.php';

?>
<!DOCTYPE html>
<html lang="zh">
  <head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <!-- The above 3 meta tags *must* come first in the head; any other head content must come *after* these tags -->
    <!-- <meta name="description" content=""> -->
    <!-- <meta name="author" content=""> -->
    <!-- <link rel="icon" href="../../favicon.ico"> -->

    <title>user manager</title>

    <!-- Bootstrap core CSS -->
    <link href="./css/bootstrap.min.css" rel="stylesheet">

    <!-- IE10 viewport hack for Surface/desktop Windows 8 bug -->
    <!-- <link href="../../assets/css/ie10-viewport-bug-workaround.css" rel="stylesheet"> -->

    <!-- Custom styles for this template -->
    <link href="./css/navbar-fixed-top.css" rel="stylesheet">

    <!-- Just for debugging purposes. Don t actually copy these 2 lines! -->
    <!--[if lt IE 9]><script src="../../assets/js/ie8-responsive-file-warning.js"></script><![endif]-->
    <!-- <script src="../../assets/js/ie-emulation-modes-warning.js"></script> -->

    <!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
    <!--[if lt IE 9]>
      <script src="https://oss.maxcdn.com/html5shiv/3.7.3/html5shiv.min.js"></script>
      <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
    <![endif]-->

    <script src="js/jquery.js"></script>
      <script src="js/jquery-3.4.1.min.js"></script>
    <script src="js/bootstrap.min.js"></script>
    <!-- IE10 viewport hack for Surface/desktop Windows 8 bug -->
    <!-- <script src="../../assets/js/ie10-viewport-bug-workaround.js"></script> -->


  </head>

  <body>

    <!-- Fixed navbar -->
	<?php include 'adminHeader.php'; ?>
	
    <div class="container">

      <!-- Main component for a primary marketing message or call to action -->
       <div class="jumbotron">
          <h1 class="display-4">User Manager</h1>
          <p class="lead">This is the user management section, where you can perform Create, Read, Update, and Delete operations on users.</p>
        </div>

        <table class="table ">

        <a href="adduser.php" class="btn btn-success">add user</a>
        <thead>
          <tr>
            <th>id</th>
            <th>username </th>
            <th>password</th>
            <th>email</th>
            <th>creator</th>
          </tr>
        </thead>
        <tbody>
      <?php
      $sql = "SELECT * FROM user where IS_DELETE = 0";
      $result = $conn->query($sql);
      if ($result->num_rows > 0) {
        while($row = $result->fetch_assoc()) {
          ?>
    <tr>
      <td><?php echo $row["U_ID"]; ?></td>
      <td><?php echo $row["U_Username"]; ?></td>
      <td><?php echo $row["U_Password"]; ?></td>
      <td><?php echo $row["U_Email"]; ?></td>
      <td>
<a href="javascript:void(0);" class="btn btn-primary" onclick="edituser('<?php echo htmlspecialchars($row['U_ID']); ?>')">edit user</a>
<button class="btn btn-danger" data-toggle="modal" onclick="deluser('<?php echo htmlspecialchars($row['U_ID']); ?>');">del user</button>      </td>
    </tr>

    <?php }
      } else {
        echo "0 result";
      }
	  
      $conn->close();
      ?>
    </tbody>
  </table>
  </div>
<!-- JavaScript -->
<script type="text/javascript">

function edituser(uid) {
    if (confirm('确定要编辑该用户吗？')) {
        window.location.href = "edituser.php?uid=" + uid;
    }
}
function deluser(uid) {
    if (confirm('are you sure？')) {
        $.post("deluser.php", {
            uid: uid
        }, function(data, status) {
            if (data === "1") {
                alert('del success！');
                setTimeout(function() {
                    location.href = "userList.php";
                }, 300);
            } else {
                alert('del fail！');
            }
        });
    }
}
</script>
  </body>

</html>
